package com.threaddemo4;

import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class SupplyAsyncDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(()->{
            System.out.println("执行 Callable!" + Thread.currentThread().getName());
            return "Hello Callable!";
        });

        String ret = f1.get();
        System.out.println("ret = " + ret);

        CompletableFuture f2 = CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行Runnable" + Thread.currentThread().getName());
            }
        });

        Object ret2 = f2.get();
        System.out.println("ret2 = " + ret2);



    }
}
